<?php

use think\migration\Seeder;

class AirQualityAqiCityRankData extends Seeder
{

    public function run()
    {
        $table = $this->table('air_quality_aqi_city_rank');
        $rows = [];

        $num  = 7;
        $i    = 0;
        while ($num > 0) {
            $conditionArr = ['优','良','轻度','中度','重度','严重'];
            $conditionKeys = array_rand($conditionArr);

            $rankOne = mt_rand(20, 318);
            $rankTwo = mt_rand(1, 26);
            $rankThree = mt_rand(1, 11);
            $rankFour = mt_rand(1, 13);
            $rows[] = [
                //step0:时间
                'publish_time'      => date('Y-m-d', time() - 3600 * 24 * $i),  //发布时间-7天前的每天

                //step:相关ID
                'region_id'         => 53,

                //step1:aqi污染情况
                'aqi'               => mt_rand(10, 300),   //长治市aqi污染情况,
                'aqi_level'         => $conditionArr[$conditionKeys],   //长治市aqi污染情况,

                //step1:全国排名
                'country_aqi_rank'  => $rankOne,
                'country_total'     => 318,
                'country_percent'   => ($rankOne / 318) * 100,

                //step2:“2+26”排名
                '28city_aqi_rank'   => $rankTwo,
                '28city_total'      => 26,
                '28city_percent'    => ($rankTwo / 26) * 100,

                //step3:全省排名
                'province_aqi_rank' => $rankThree,
                'province_total'    => 11,
                'province_percent'  => ($rankThree / 11) * 100,

                //step4:汾渭平原排名
                'fenwei_aqi_rank'   => $rankFour,
                'fenwei_total'      => 13,
                'fenwei_percent'    => ($rankFour / 13) * 100,


                'create_time'       => date('Y-m-d H:i:s', time()),
            ];
            $num--;
            $i++;
        }

        $table->insert($rows)->save();
    }

    public function data()
    {
        $data = file_get_contents(__DIR__ . '/json/city_rank.json');
        return $data;
    }
}